{extend name="base" /}
{block name="title"}合计业绩{/block}
{block name="head"}{/block}
{block name="body"}

<div class="weui_panel ms-controller" ms-controller="weixin">
  <div class="weui_panel_hd f-black">
    <div class="weui-flex">
      <div class="weui-flex-item">邀请码: {{@GameID}}</div>
      <div class="weui-flex-item weui_cells_access">
        <a class="weui_cell" style="padding:0" href="{:url('cashconfirm')}">
          <div class="weui_cell_bd weui_cell_primary">总业绩: <span class="f-red">{{@rebate|currency}}</span></div>
          <div class="weui_cell_ft"></div>
        </a>
      </div>
    </div>
  </div>
  <div class="weui_panel_bd">
    <table class="weui-table">
      <thead>
        <tr><th>#</th><th>业绩</th><th>时间</th></tr>
      </thead>
      <tbody>
        <tr ms-if="@rows.length<=0"><td colspan="3">Oh~暂无数据!</td></tr>
        <tr ms-if="@rows.length>0" ms-for="(k,v) in @rows" ms-class="[@v.AccountsType==1&&'f-red']">
          <td>{{v.ROW_NUMBER}}</td>
          <td>{{v.RMB}}</td>
          <td>{{v.CollectDate|date('MM/dd HH:mm')}}</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="weui_panel_ft" style="padding:0;">
    <div class="weui-flex pager">
      <a class="weui-flex-item" ms-on-tap="@tapFirst">首页</a>
      <a class="weui-flex-item weui-border-l" ms-on-tap="@tapPre">上一页</a>
      <a class="weui-flex-item weui-border-l">{{@page}}/{{@totalPage}}</a>
      <a class="weui-flex-item weui-border-l" ms-on-tap="@tapNext">下一页</a>
      <a class="weui-flex-item weui-border-l" ms-on-tap="@tapEnd">尾页</a>
    </div>
  </div>
</div>

{/block}
{block name="foot"}
<script>
avalon.ready(function () {

  var vm = avalon.define({
    $id: "weixin",
    page: "{$page??1}" * 1, // 当前第几页
    size: "{$size??10}" * 1, // 每页几条
    total: "{$total??0}" * 1, // 总共几条
    GameID: "{$info.GameID??0}",  // 邀请码
    rebate: "{$info.rebate??0}" * 1,  // 可提现佣金
    rows: {:json_encode($rows??[], JSON_UNESCAPED_UNICODE)},
    $computed: {
      totalPage: {
        get: function () {
          var max = Math.ceil(this.total / this.size); // 最大页数=向上取整
          max = max > 0 ? max : 1;
          return max;
        }
      }
    },
    ajaxPage: function (page) {
      $.req({
        type: 'POST',
        url: "{:url('weixin')}",
        data: {
          page: page
        },
        success: function (resp, status, xhr) {
          avalon.log(resp);
          if (resp.errno == 0) {
            vm.page = resp.data.page * 1;
            vm.size = resp.data.size * 1;
            vm.total = resp.data.total * 1;
            vm.rebate = resp.data.info.rebate * 1;
            vm.GameID = resp.data.info.GameID;
            vm.rows.removeAll();
            vm.rows.pushArray(resp.data.rows);
          }
        }
      });
    },
    tapFirst: function () {
      avalon.log("tapFirst");
      this.ajaxPage(1);
      return false;
    },
    tapPre: function () {
      avalon.log("tapPre");
      var page = this.page - 1;
      page = page > 0 ? page : 1;
      this.ajaxPage(page);
      return false;
    },
    tapNext: function () {
      avalon.log("tapNext");
      var page = this.page + 1;
      page = page > this.totalPage ? this.totalPage : page;
      this.ajaxPage(page);
      return false;
    },
    tapEnd: function () {
      avalon.log("tapEnd");
      this.ajaxPage(this.totalPage);
      return false;
    }
  });
  avalon.scan(document.body);
});
</script>
{/block}